//
//  WXAnimationController.m
//  TestWeb
//
//  Created by tianlong on 2018/8/15.
//  Copyright © 2018年 tianlong. All rights reserved.
//

#import "WXAnimationController.h"
#import "WXAnimationManager.h"
#import "Masonry.h"
#import "WXButton.h"

@interface WXAnimationController ()<UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UIView *view1;
@property (nonatomic,   copy) NSString *aniJson_shakeBox;
@property (strong, nonatomic) IBOutlet UIPanGestureRecognizer *dragGesture;
@end

@implementation WXAnimationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    WXButton *btn = [WXButton buttonWithType:UIButtonTypeSystem];
    btn.backgroundColor = [UIColor greenColor];
    [btn setTitle:@"点击测试" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(UIControlEventTouchDown) forControlEvents:UIControlEventTouchDown];
    [btn addTarget:self action:@selector(UIControlEventTouchUpOutside) forControlEvents:UIControlEventTouchUpOutside|UIControlEventTouchUpInside];
    [self.view1 addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-20);
        make.top.offset(70);
        make.width.offset(100);
        make.height.offset(50);
    }];
    
    self.dragGesture.delegate = self;
}

- (IBAction)controlVolumeAndProgress:(UIPanGestureRecognizer *)sender {
    
    NSLog(@"%s_senderClass = %@",__FUNCTION__,NSStringFromClass([sender class]));
}


-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    NSLog(@"touch.view_class = %@",NSStringFromClass([touch.view class]));
    if([touch.view isKindOfClass:[WXButton class]])
    {
        return NO;
    }
    return YES;
}

- (IBAction)tap:(id)sender {
    
}

- (void)tapCommendCover:(UITapGestureRecognizer *)tap {
    NSLog(@"tap.state=%ld",(long)tap.state);
}

- (void)UIControlEventTouchDown {
    NSLog(@"TouchDown------------");
}

- (void)UIControlEventTouchUpInside {
    NSLog(@"TouchUpInside------------");
}

- (void)UIControlEventTouchUpOutside {
    NSLog(@"TouchUpOutside------------");
}

- (void)UIControlEventTouchCancel {
    NSLog(@"UIControlEventTouchCancel------------");
}

- (void)UIControlEventTouchDragOutside {
//     NSLog(@"UIControlEventTouchDragOutside------------");
}

- (void)UIControlEventTouchDragInside {
//     NSLog(@"UIControlEventTouchDragInside------------");
}

#pragma mark - 宝箱抖动
- (IBAction)shakeBox:(id)sender {
    self.aniJson_shakeBox = @"golden_shake";
    if ([WXAnimationManager getAnimationByIdentifier:self.aniJson_shakeBox]) {
        NSLog(@"shakeBox____已存在");
        return;
    }
    
    __weak typeof(self)selfWeak = self;
    [WXAnimationManager playWithJson:self.aniJson_shakeBox speed:1 repeatCount:INT_MAX identifier:self.aniJson_shakeBox layout:^(WXAnimationView *aniView) {
        [self.view addSubview:aniView];
        aniView.backgroundColor = [UIColor greenColor];
        [aniView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(0);
            make.top.offset(0);
            make.width.offset(300);
            make.height.offset(375);
        }];
        
        UIImageView *bindingBox = [[UIImageView alloc] init];
        bindingBox.backgroundColor = [UIColor blackColor];
        [aniView bindingUIView:bindingBox forKeyPath:@"宝箱关" imageName:@"golden_shake_0.png"];
        
        UIButton *clickedBoxBtn = [[UIButton alloc] init];
        clickedBoxBtn.backgroundColor = [UIColor redColor];
        [clickedBoxBtn addTarget:self action:@selector(clickedBoxBtn) forControlEvents:UIControlEventTouchUpInside];
        [aniView addSubview:clickedBoxBtn];
        clickedBoxBtn.alpha = 0.7;
        [clickedBoxBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.right.offset(0);
        }];
        
    } autoPlay:YES completion:^(BOOL finished) {
        [WXAnimationManager stopAniamtionWithIdentifier:selfWeak.aniJson_shakeBox];
        NSLog(@"动画播放完成");
    }];
}

- (IBAction)stopShakeBox:(id)sender {
    [WXAnimationManager stopAniamtionWithIdentifier:self.aniJson_shakeBox];
}


- (void)clickedBoxBtn {
    NSLog(@"%s",__FUNCTION__);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
